/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simple;

import algorithm.Genotype;
import java.util.Arrays;

/**
 *
 * @author Pierre
 */
public class BitStringGenotype implements Genotype {
    private short[] bits;

    BitStringGenotype(short[] bits) {
        this.bits = bits.clone();
    }
    public int getLength() {
        return bits.length;
    }
    public short[] getBits() {
        return bits;
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        BitStringGenotype ret = (BitStringGenotype) super.clone();
        ret.bits = Arrays.copyOf(bits, bits.length);
        return ret;
    }

    void flipBit(int index) {
       if (bits[index] == (short)0) {
           bits[index] = (short)1;
       } else {
           bits[index] = (short)0;
       }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final BitStringGenotype other = (BitStringGenotype) obj;
        if (this.bits != other.bits && (this.bits == null || !this.bits.equals(other.bits))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + (this.bits != null ? this.bits.hashCode() : 0);
        return hash;
    }
    
    

}
